# -*- coding: utf-8 -*-
#
# Author:: Jonny
# Date:: 2020/12/12
import os
import re
import shutil

from submodules.common.lib.platform_ import is_mac, is_windows


def listdir_rec(target_path):
    json_file_path_list = []
    for dirpath, dirnames, filenames in os.walk(target_path):
        for item in filenames:
            json_file_path_list.append(os.path.join(dirpath, item))
    return json_file_path_list


def mkdir_soft(*args, **kwargs):
    try:
        os.mkdir(*args, **kwargs)
    except Exception as e:
        pass

def rmtree_soft(*args, **kwargs):
    try:
        shutil.rmtree(*args, **kwargs)
    except Exception as e:
        pass


def makedirs_softly(dir_path):
    if os.path.isdir(dir_path) and os.path.exists(dir_path):
        pass
    else:
        os.makedirs(dir_path)


def get_local_chrome_version():
    if is_mac():
        cmd_res = os.popen('''
            grep -r "Copyright 20[0-9][0-9] Google LLC. Alle Rechte vorbehalten." /Applications/Google\ Chrome.app/Contents/Resources/de.lproj/InfoPlist.strings |grep "CFBundleGetInfoString"
            ''').read()
        patten = re.compile("[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*")
        res = patten.findall(cmd_res)
        chrome_head_version = res[0].split('.')[0]
        return chrome_head_version
    elif is_windows():
        pass


if __name__ == "__main__":
    pass
